#ifndef STORAGE_H_
#define STORAGE_H_
#include <iostream>
#include <string>
#include <memory>
#include <map>
#include "PtrMap.h"
#include "Regex.h"

typedef unsigned long int Atom;


extern std::string emptyString;
typedef PtrMap<Atom, std::string>  ValuesMap;
typedef PtrMap<Atom, Regex> FiltersMap;

class Storage {	
	static Storage *instance_;
	ValuesMap values_;
	FiltersMap filters_;
	std::auto_ptr<std::string> value_;
	Storage() : values_(), filters_(), value_(new std::string("")){
		//std::cout<<"calling storage constructor "<<std::endl;
	};
	
	~Storage(){};
	void replace(std::string ** target, std::string * source);
	bool empty(std::string *s) ;
	bool passFilter(Atom atom, std::string* ownerName);
public:
	static Storage* getInstance(){
		if (instance_ == NULL) {
			instance_ = new Storage();
		}	
		return instance_;
	}
	
	void updateValue(Atom atom, std::string* ownerName, std::string* value);
	static void update(Atom atom, std::string* ownerName, std::string* value) {
		getInstance()->updateValue(atom, ownerName, value); 
	}
	
	void setFilterString( Atom atom, std::string* re);
	static void setFilter( Atom atom, std::string* re) {
		getInstance()->setFilterString(atom, re);
	}
	
	std::string*  getValue() {
		//std::cout << "Returning '" << *value_ <<"from storage"<<std::endl;
		return value_.get();
	}
	static std::string* get() { return getInstance()->getValue(); }	
};

#endif /*STORAGE_H_*/
